<template>
	<view class="content">
		<u-navbar title="甘肃碳交" bgColor="#c30d23" :titleStyle="titleStyle" safeAreaInsetTop placeholder>
			<view slot="left"></view>
		</u-navbar>
		 <u-swiper
		           :list="list1"
		           indicator
				   height="180"
				   indicatorMode="dot"
		    ></u-swiper>
		<view class="infromBox">
			<view class="infrom f-between-center" @click="toinfrom">
				<view class="f-start-center" >
					<u-icon name="volume-fill" color="#000000" size="16"></u-icon>
					<text style="margin-left: 14rpx;font-size: 28rpx;color: #323233;">通知公告</text>
				</view>
				<view class="f-start-center">
					<text class="more">更多</text>
					<u-icon name="arrow-right" color="#969799" size="16"></u-icon>
				</view>
			</view>
			<view class="consult">
				<view class="infrom f-between-center">
					<view class="f-start-center">
						<u-icon name="/static/personal/hot.png" color="#000000" size="18"></u-icon>
						<text style="margin-left: 14rpx;font-weight: bold;font-size: 32rpx;">市场资讯</text>
					</view>
					<view class="f-start-center">
						<text class="more">更多</text>
						<u-icon name="arrow-right" color="#969799" size="16"></u-icon>
					</view>
				</view>
				<u-line></u-line>
				<view class="article" v-for="(n,m) in consultList" :key="m" @click="toDetail(n.id)">
					<view class="infrom f-between-center">
						<view class="title">
							{{n.title}}
						</view>
						<view class="time">
							{{n.time}}
						</view>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {getUserInfo,userLogin} from "@/api/user.js"
	export default {
		data() {
			return {
				list1:[
					"http://8.130.178.15:8070/onlineopen/uploadFile/20231012/202310121058109755.jpg",
					"http://8.130.178.15:8070/onlineopen/uploadFile/20231012/202310121058212682.jpg"
				],
				titleStyle: {
					color: "#ffffff",
					fontSize: "36rpx",
					fontWeight: '400'
				},
				consultList:[
				]
			}
		},
		onLoad(e) {
			this.getdata()
		},
		methods: {
			
			toinfrom(){
				uni.navigateTo({
					url:'/pages/index/inform'
				})
			},
			getdata(){
				uni.request({
					url:'http://8.130.69.63:8280/api/Common/QueryNewTitles?page=1&pagesize=10',
					method:"GET",
					success: (res) => {
						console.log(res.data.data)
						let arr = res.data.data
						arr.forEach(item => {
						    const updateTime = new Date(item.updatedate);
						    const month = updateTime.getMonth() + 1; // Months are zero-indexed
						    const day = updateTime.getDate();
						
						    // Pad single-digit months or days with a leading zero
						    const formattedMonth = month < 10 ? `0${month}` : month;
						    const formattedDay = day < 10 ? `0${day}` : day;
						
						    // Add 'time' property in the format 'MM-DD'
						    item.time = `${formattedMonth}-${formattedDay}`;
						});
						this.consultList = arr
					}
				})
				//this.$util.isLogin('login') 加参数时如果token为空则直接跳转到登录页
				// if(this.$util.isLogin()){
				// 	//获取用户信息,拦截器里已经判断是否有token,所以这里无需写token参数
				// 	getUserInfo().then(res => {
				// 		console.log(res)
				// 	})
				// }else{
				// 	//获取用户信息
				// 	userLogin({username:'zhangsan',password:'1234'}).then(res => {
				// 		console.log(res)
				// 	})
				// }
			},
			toDetail(id){
				uni.navigateTo({
					url:'/pages/index/detail?id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-swiper{
		width: 100% !important;
	}
	.more{
		color: #969799;
		font-size: 28rpx;
	}
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.infromBox{
		margin-top: 20rpx;
		width: 100%;
		box-sizing: border-box;
		padding: 0 20rpx;
		.infrom {
			width: 100%;
			height: 88rpx;
			background: #fff;
			border-radius: 5px;
			padding-left: 20rpx;
			padding-right: 20rpx;
			box-sizing: border-box;
		}
		.consult{
			min-height: 240rpx;
			margin: 20rpx 0px;
			background: #fff;
			border-radius: 5px;
			box-sizing: border-box;
			padding: 0 20rpx;
			.infrom{
				padding-left: 0rpx;
				padding-right: 0rpx;
			}
		}
		.article {
			font-size: 26rpx;
			.time {
				color: gray;
			}
			.title{
				width: 82%;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
		}
	}
</style>
